//PhoneGap is ready
function onDeviceReady() {
	loadPlaylist();
}

//Setting up jQuery
$(document).ready(function () {
	displayLoadingSplash();
	// Wait for PhoneGap to load
	document.addEventListener("deviceready", onDeviceReady, false);  
});

var pendingAjaxCall = "false";

//ajax call to populate playlist
function loadPlaylist() {
	if(pendingAjaxCall == "false"){
		pendingAjaxCall = "true";
	  $.ajax({
          type: "POST",
          url: "http://novaapps.wooyea.com/sarangi/service/playlistservice.asmx/GetPlayList",
          contentType: "application/json; charset=utf-8",
          data: "{}",
          dataType: "json",
          success: AjaxSucceeded,
          error: AjaxFailed
      });
	}
}


function AjaxSucceeded(result) {
    var playItems = result.d;
    
    $.each(playItems, function (index, item) {
    	populatePlaylist(item);
    });
    pendingAjaxCall = "false";
}

function AjaxFailed(result) {
    alert("Sorry, could not talk to the server :( Please make sure your data is working.");
    pendingAjaxCall = "false";
}

//function to exit the app
function exitApp(){
	var quit = confirm ('Are you sure you want to exit?');
	if(quit){
		navigator.app.exitApp();
	}
	else
		return false;
}
